package br.com.scpe.util;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import br.com.scpe.ejb.entity.Funcionario;

public abstract class Sessao {
	private HttpSession session;

	protected HttpSession getSession() {
		return session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true);
	}
	
	protected void setSession(String argumento, Funcionario funcionario) {
		session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(true);
		session.setAttribute(argumento, funcionario);
	}
	
	protected void destruir(){
		session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		session.invalidate();
	}
	
	protected boolean sessaoExiste(String argumento){
		boolean result = (getSession().getAttribute(argumento) != null);
		return result;
	}
	
	public static Sessao getInstance(){
		return new Sessao() {
		};
	}
	
}
